<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="HandheldFriendly" content="true" />
    <meta name="MobileOptimized" content="320" />
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/jiazai.css">
    <title>重置交易密码</title>
    <style>
        .notice-hea {
            position: fixed;
            top: 0;
            right: 0;
            left: 0;
            height: 40px;
            padding: 0 20px;
            display: flex;
            align-items: flex-end;
        }
        
        .notice-hea>span {
            margin-left: 18px;
            font-size: 17px;
        }
        
        .set-trans-wrap {
            position: fixed;
            top: 40px;
            left: 0;
            right: 0;
            bottom: 0;
            padding: 20px;
            overflow: auto;
        }
        
        .set-list {
            margin-top: 30px;
            padding: 8px 0;
            display: flex;
            align-items: center;
            font-size: 14px;
            border-bottom: 1px solid #eee;
        }
        
        .set-list>span {
            flex: 0 0 80px;
        }
        
        .set-list>input {
            flex: 1 1 0;
            letter-spacing: 2px;
        }
        
        .btn-sure {
            width: 70%;
            margin: 100px 15% 0;
            padding: 8px 0;
            font-size: 15px;
            letter-spacing: 2px;
            color: white;
            background: #3574FA;
            border-radius: 5px;
            box-shadow: 1px 1px 10px RGBA(53, 116, 250, .7);
        }
    </style>
</head>

<body>
    <div id='app'>
        <!-- 加载中动画 -->
        <div class='jiazai' v-if='jiazai'>
            <img src="./img/jia-ani.gif" width="50px" height="50px">
        </div>
        <!-- 加载中动画 -->
        <div class='notice-hea'>
            <img @click='close' src="./img/right-black.svg" width="20px" height="20px">
            <span>重置交易密码</span>
        </div>
        <div class='set-trans-wrap'>
            <div class='set-list'>
                <span>新密码</span>
                <input type="password" placeholder="请输入6位数字" v-model='pass'>
            </div>
            <div class='set-list'>
                <span>确认密码</span>
                <input type="password" placeholder="再次确认密码" v-model='surePass'>
            </div>
            <button class='btn-sure' @click='sub'>确认提交</button>
        </div>
    </div>
    <script src="js/comm.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/back.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/vue.min.js"></script>
    <script>
        var user = function(data) {
            app.$data.user = JSON.parse(data);
        }
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                //上级传过来的user
                user: {},
                //新密码
                pass: '',
                //确认新密码
                surePass: ''
            },
            methods: {
                close: function() {
                    var web = plus.webview.currentWebview();
                    web.close('none');
                },
                sub: function() {
                    var passLen = this.pass.length;
                    if (String(parseInt(this.pass)).length != 6 || this.pass.indexOf('.') != -1 || this.pass.indexOf('-') != -1) {
                        _toast('您的交易密码不符合要求');
                        return;
                    }
                    if (this.pass != this.surePass) {
                        _toast('您两次交易密码不一致');
                        return;
                    }
                    var This = this;
                    this.jiazai = true;
                    _post(FORGET_PASSWORD2, {
                        userid: this.user.userid,
                        type: this.user.type,
                        password1: this.pass,
                        password2: this.surePass
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            _toast('重置密码成功，请牢记你的新密码');
                            var index = plus.webview.getWebviewById('index');
                            if (index) {
                                index.show();
                                var all = plus.webview.all();
                                var indexUrl = index.getURL();
                                setTimeout(function() {
                                    for (var i = 0; i < all.length; i++) {
                                        if (all[i].getURL() != indexUrl) {
                                            all[i].hide();
                                        }
                                    }
                                }, 1000);
                                setTimeout(function() {
                                    for (var i = 0; i < all.length; i++) {
                                        if (all[i].getURL() != indexUrl) {
                                            all[i].close('none');
                                        }
                                    }
                                }, 2000);
                            } else {
                                plus.webview.getWebviewById('login').show();
                                var forgetPassword = plus.webview.getWebviewById('forgetPassword');
                                var curr = plus.webview.currentWebview();
                                forgetPassword.hide();
                                curr.hide();
                                setTimeout(function() {
                                    forgetPassword.close('none');
                                    curr.close('none');
                                }, 3000);
                            }
                        } else {
                            _toast(data.msg);
                        }
                    });
                }
            }
        });
    </script>
    <script type="text/javascript" charset="utf-8">
        function plusReady() {

        }

        // 判断扩展API是否准备，否则监听'plusready'事件
        if (window.plus) {
            plusReady();
        } else {
            document.addEventListener('plusready', plusReady, false);
        }
    </script>
</body>

</html>